import WS from '@/api/ws'
import store from '@/store'
import { ref, onMounted } from 'vue'
const useTodoWs = () => {
    const methodName = 'to_do_list_count'
    const onMarkersList = data => {
        store.commit('setTodoCount', data?.todoCount)
    }
    const onNewMessage = () => {
        store.commit('setNewMessage')
    }
    let ws = ref(null)
    ws = WS.instance(store.getters.idUser)
    onMounted(() => {
        ws.sub(methodName, onMarkersList)
        // 如果之前的这个to_do_list_count事件不需要了注释掉上面一行就可以了
        // 下面这个事件是消息推送模块的，不能删除
        ws.sub('to_do_message', onNewMessage)
    })
}

export default useTodoWs
